package com.whpost.api.controller.index;


import cn.dev33.satoken.annotation.SaCheckLogin;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.whpost.api.entity.ReqInfo;
import com.whpost.api.utils.ApiUtils;
import com.whpost.service.dao.stamp.StampCardOrderMapper;
import com.whpost.service.entity.tools.ResultInfo;
import com.whpost.service.service.t.IndexServices;
import com.whpost.service.service.t.TApiNonceService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.crypto.NoSuchPaddingException;
import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.text.ParseException;
import java.util.Map;

@RestController()
public class ApiIndexController {

    @Resource
    private IndexServices indexServices;

    @Resource
    private TApiNonceService tApiNonceService;

    @Resource
    private StampCardOrderMapper stampCardOrderMapper;

    /**
     *
     * @return
     */
    @SaCheckLogin
    @RequestMapping(value ="/index")
    public ResultInfo index() throws UnsupportedEncodingException {
        String loginId = ApiUtils.getLoginId();
        return indexServices.init(loginId);
    }

    /**
     * 获取nonce
     * @param map
     * @return
     */
    @RequestMapping("/getnonce")
    @ResponseBody
    public ResultInfo getNonce(@RequestBody Map<String, Object> map){
        String loginId = ApiUtils.getLoginId();
        return tApiNonceService.getNonce(loginId,map);
    }

    /**
     * test
     * @return
     */
    @RequestMapping(value ="/test")
    public String test() throws UnsupportedEncodingException, ParseException {
        return "ok";
    }
}
